# -*- coding: utf-8 -*-
# /usr/bin/env python

# --- import area ---
from __future__ import division
from __future__ import print_function

# --- import end ---


def filter_id(dicts, filter_list, filter_dict ):
    """
    333223
    abbbb

    """

    try:
        assert isinstance(dicts, dict)
        for k, v in dicts.items():
            for x in range(len(filter_list)):
                if k == filter_list[x]:
                    dicts.pop(k)
                    if not filter_dict.has_key(k):
                        filter_dict[k] = 1
                        continue
                    filter_dict[k] += 1
                try:
                    assert isinstance(v, dict)
                    filter_id(v, filter_list, filter_dict)
                except AssertionError:
                    pass
        return dicts, filter_dict
    except AssertionError:
        print ("There have a type error!!")

if __name__ == '__main__':
    dict1 = {'id': 1, 'name': 'lilei', 'age': 12,
             'teacher': {'math': {'id': 2, 'name': 'James', 'age': 30}, 'china': {'id': 4, 'name': 'hello', 'age': 32}}}
    filter_list = ['id', 'teacher']
    filter_dict = {}
    f = filter_id(dict1, filter_list, filter_dict)
    print (f)
